package presale_house.handler;

import presale_house.entity.ClientDo;
import presale_house.entity.HouseDo;
import presale_house.service.ClientService;
import presale_house.service.HouseService;
import presale_house.service.impl.ClientServiceImpl;
import presale_house.service.impl.HouseServiceImpl;
import presale_house.show.HouseList.HouseView;
import presale_house.show.MainView;
import presale_house.show.view.UpdateClientView;
import presale_house.show.view.UpdateHouseView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateHouseViewHandler implements ActionListener {
    private UpdateHouseView updateHouseView;
    private HouseView houseView;
    public UpdateHouseViewHandler(UpdateHouseView updateHouseView, HouseView houseView){
        this.updateHouseView = updateHouseView;
        this.houseView=houseView;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text=jButton.getText();
        if("修改".equals(text)){
          HouseService houseService =new HouseServiceImpl();
            HouseDo houseDo =  updateHouseView.buildUpdateHouse();
            boolean updateResult= houseService.update(houseDo);
            if(updateResult){
                //更新表格数据
                houseView.reloadTable();
                updateHouseView.dispose();
                JOptionPane.showMessageDialog( updateHouseView,"修改成功");
            }else{
                JOptionPane.showMessageDialog( updateHouseView,"修改失败");
            }
        }
    }
}
